/*
 * Copyright (C) 2014 Jörg Wiesmann
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
package de.inetsource.onepagejsf.html;

import java.util.HashMap;
import java.util.LinkedHashMap;

/**
 * @author Jörg Wiesmann
 */
public class Utils {

    static HashMap<String, String> generateAttributes(String... values) {
        if (values != null && values.length > 0 && (values.length % 2 == 0)) {
            HashMap<String, String> resultMap = new LinkedHashMap<>();
            int i = 0;
            String key = null;
            for (String value : values) {
                i++;
                if (i % 2 == 0) {
                    resultMap.put(key, value);
                } else {
                    key = value;
                }
            }
            return resultMap;
        } else {
            throw new IllegalArgumentException("parameter is not valid. Must be not null and have a key/value pair (mod2=0)");
        }
    }
}
